/* -*- c++ -*- */
/*
 * Copyright 2007 Free Software Foundation, Inc.
 *
 * This file is part of GNU Radio
 *
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifndef INCLUDED_XSTAR_REED_SOLOMON_H
#define INCLUDED_XSTAR_REED_SOLOMON_H

#include <gr_runtime.h>
#include <string>

class xstar_reed_solomon;
typedef boost::shared_ptr<xstar_reed_solomon> xstar_reed_solomon_sptr;

/*!
 * \brief Initialize a Reed-Solomon encoder/decoder
 *
 * The encoder will take \p packet_size - \p fec_size long strings,
 * and return \p fec_size bytes of FEC code.
 *
 * The decoder will return \p packet_size - \p fec_size long strings
 * or an empty string if there are uncorrectable errors.
 */
xstar_reed_solomon_sptr
xstar_make_reed_solomon (int packet_size, int fec_size);

/*!
 * \brief Forward Error Correction using Reed-Solomon
 *
 * Create parity data and verify/correct using Reed-Solomon
 *
 * Supports packet_sizes of up to 255 bytes (including FEC data)
 */
class xstar_reed_solomon
{
  friend xstar_reed_solomon_sptr
  xstar_make_reed_solomon (int packet_size, int fec_size);

 private:
  void *d_rs;
  int d_packet_size;
  int d_fec_size;

 protected:
  xstar_reed_solomon(int packet_size, int fec_size);

 public:
  /*!
   * \brief Create FEC data given a payload
   *
   * The returned string contains only the FEC-data of (fec_size bytes)
   */
  std::string encode(char *packet);

  /*!
   * \brief Verify packet and correct errors if possible
   *
   * The returned string contains only the payload, no FEC
   *
   * If there are uncorrectable errors an empty string is returned.
   */
  std::string decode(char *packet);

  ~xstar_reed_solomon();
};

#endif /* INCLUDED_XSTAR_REED_SOLOMON_H */
